J.D. Meier, Alex Mackman, Michael Dunner, and
Srinath Vasireddy
Microsoft Corporation
November 2002
Applies to:
Microsoft® ASP.NET
See the Landing Page for the starting point and a complete overview of Building Secure ASP.NET Applications.
Summary: This chapter describes the common characteristics of .NET Web applications from a security perspective and introduces the .NET Web application security model. It also introduces the set of core implementation technologies that you will use to build secure .NET Web applications. (16 printed pages)
.NET Web Applications
Implementation Technologies
Security Architecture
Identities and Principals
Summary
This chapter introduces .NET Web application security. It provides an overview of the security features and services that span the tiers of a typical .NET Web application.
The goal of the chapter is to:
This section provides a brief introduction to .NET Web applications and describes their characteristics both from a logical and physical viewpoint. It also provides an introduction to the various implementation technologies used to build .NET Web applications.
Logical application architecture views any system as a set of cooperating services grouped in the following layers:
The value of this logical architecture view is to identify the generic types of services invariably present in any system, to ensure proper segmentation and to drive the definition of interfaces between tiers. This segmentation allows you to make more discreet architecture and design choices when implementing each layer, and to build a more maintainable application.
The layers can be described as follows:
The logical classification of service types within a system may correlate with, but is relatively independent from, the possible physical distribution of the components implementing the services.
It is also important to remember that the logical tiers can be identified at any level of aggregation; that is, the tiers can be identified for the system as a whole (in the context of its environment and external interactions) and for any contained subsystem. For example, each remote node that hosts a Web service consists of User Services (handling incoming requests and messages), Business Services and Data Services.
The three logical service layers described earlier, in no way imply specific numbers of physical tiers. All three logical services may be physically located on the same computer, or they may be spread across multiple computers.
A common deployment pattern for .NET Web applications is to locate business and data access components on the Web server. This minimizes the network hops, which can help performance. This model is shown in Figure 2.1.

Figure 2.1. The Web server as an application server
The remote application tier is a common deployment pattern, particularly for Internet scenarios where the Web tier is self-contained within a perimeter network (also known as DMZ, demilitarized zone, and screened subnet) and is separated from end users and the remote application tier with packet filtering firewalls. The remote application tier is shown in Figure 2.2.

Figure 2.2. The introduction of a remote application tier
.NET Web applications typically implement one or more of the logical services by using the following technologies:
ASP.NET is typically used to implement User Services. ASP.NET provides a pluggable architecture that can be used to build Web pages. For more information about ASP.NET, see the following resources:
Enterprise Services provide infrastructure-level services to applications. These include distributed transactions and resource management services such as object pooling for .NET components. For more information about Enterprise Services, see the following resources:
Web services enable the exchange of data and the remote invocation of application logic using SOAP-based message exchanges to move data through firewalls and between heterogeneous systems. For more information about Web services, see the following resources:
.NET Remoting provides a framework for accessing distributed objects across process and machine boundaries. For more information about .NET Remoting, see the following resources:
ADO.NET provides data access services. It is designed from the ground up for distributed Web applications, and it has rich support for the disconnected scenarios inherently associated with Web applications. For more information about ADO.NET, see the following resources:
SQL Server provides integrated security that uses the operating system authentication mechanisms (Kerberos or NTLM). Authorization is provided by logons and granular permissions that can be applied to individual database objects. For more information about SQL Server 2000, see the following resources:
IPSec provides point-to-point, transport level encryption and authentication services. For more information about IPSec, see the following resources:
SSL provides a point-to-point secure communication channel. Data sent over the channel is encrypted. For more information about SSL, see the following resources:
Figure 2.3 shows the remote application tier model together with the set of security services provided by the various technologies introduced earlier. Authentication and authorization occurs at many individual points throughout the tiers. These services are provided primarily by Internet Information Services (IIS), ASP.NET, Enterprise Services and SQL Server. Secure communication channels are also applied throughout the tiers and stretch from the client browser or device, right through to the database. Channels are secured with a combination of Secure Sockets Layer (SSL) or IPSec.

Figure 2.3. Security architecture
The authentication, authorization, and secure communication features provided by the technologies discussed earlier are summarized in Table 2.1.
Table 2.1. Security features
| Technology | Authentication | Authorization | Secure Communication |
|---|---|---|---|
| IIS | Anonymous Basic Digest Windows Integrated (Kerberos/NTLM) Certificate |
IP/DNS Address
Restrictions Web Permissions NTFS Permissions; Windows Access Control Lists (ACLs) on requested files |
SSL |
| ASP.NET | None (Custom) Windows Forms Passport |
File
Authorization URL Authorization Principal Permissions .NET Roles |
|
| Web services | Windows None (Custom) Message level authentication |
File
Authorization URL Authorization Principal Permissions .NET Roles |
SSL and Message level encryption |
| Remoting | Windows | File
Authorization URL Authorization Principal Permissions .NET Roles |
SSL and message level encryption |
| Enterprise Services | Windows | Enterprise
Services (COM+) Roles NTFS Permissions |
Remote Procedure Call (RPC) Encryption |
| SQL Server 2000 | Windows (Kerberos/NTLM) SQL authentication |
Server logins Database logins Fixed database roles User defined roles Application roles Object permissions |
SSL |
| Windows 2000 | Kerberos NTLM |
Windows ACLs | IPSec |
The .NET Framework on Windows 2000 provides the following authentication options:
ASP.NET authentication modes include Windows, Forms, Passport and None.
Note
Basic authentication should only be used in conjunction with a secure channel (typically established by using SSL). Otherwise, user names and passwords can be easily stolen with network monitoring software. If you use Basic authentication you should use SSL on all pages (not just a logon page), because credentials are passed on all subsequent requests. For more information about using Basic authentication with SSL, see Chapter 8, "ASP.NET Security."
Forms authentication is sometimes used solely for Web site personalization. In this case, you need write little custom code because ASP.NET handles much of the process automatically with simple configuration. For personalization scenarios, the cookie needs to hold only the user name.
Note
Forms authentication sends the user name and password to the Web server in plain text. As a result, you should use Forms authentication in conjunction with a channel secured by SSL. For continued protection of the authentication cookie transmitted on subsequent requests, you should consider using SSL for all pages within your application and not just the logon page.
For more details about ASP.NET authentication, see Chapter 8, ASP.NET Security.
Enterprise Services authentication is performed by using the underlying Remote Procedure Call (RPC) transport infrastructure, which in turn uses the operating system Security Service Provider Interface (SSPI). Clients of Enterprise Services applications may be authenticated using Kerberos or NTLM authentication.
A serviced component can be hosted in a Library application or Server application. Library applications are hosted within client processes and as a result assume the client's identity. Server applications run in separate server processes under their own identity. For more information about identity, see the "Identities and Principals" section later in this chapter.
The incoming calls to a serviced component can be authenticated at the following levels:
For more information about Enterprise Services authentication, see Chapter 9, Enterprise Services Security.
SQL Server can authenticate users by using Windows authentication (NTLM or Kerberos) or can use its own built-in authentication scheme referred to as SQL authentication. The following two options are available:
The relative merits of each approach are discussed in Chapter 12, "Data Access Security."
The .NET Framework on Windows 2000 provides of the following authorization options:
ASP.NET authorization options can be used by ASP.NET Web applications, Web services and remote components. ASP.NET provides the following authorization options:
URL Authorization requires an authenticated identity. This can be obtained by a Windows or ticket-based authentication scheme.
You can use it to restrict access to specified files on a Web server. Access permissions are determined by Windows ACLs attached to the files.
.NET roles can be used to control access to resources and operations and they can be configured both declaratively and programmatically.
For more information about ASP.NET authorization, see Chapter 8, ASP.NET Security.
Access to functionality contained in serviced components within Enterprise Services applications is governed by Enterprise Services role membership. These are different from .NET roles and can contain Windows group or user accounts. Role membership is defined within the COM+ catalog and is administered by using the Component Services tool.
For more information about Enterprise Services authorization, see Chapter 9, Enterprise Services Security.
SQL Server allows fine-grained permissions that can be applied to individual database objects. Permissions may be based on role membership (SQL Server provides fixed database roles, user defined roles and application roles), or permission may be granted to individual Windows user or group accounts.
For more information about SQL Server authorization, see Chapter 12, Data Access Security.
Throughout the remainder of this document, the term gatekeeper is used to identify the technology that is responsible for a gate. A gate represents an access control point (guarding a resource) within an application. For example, a resource might be an operation (represented by a method on an object) or a database or file system resource.
Each of the core technologies listed earlier provide gatekeepers for access authorization. Requests must pass through a series of gates before being allowed to access the requested resource or operation. The following describes the gates the requests must pass through:
IIS checks Web permissions, followed by NTFS file permissions. A user must be authorized by both mechanisms for them to be able to access the file or folder. A failed Web permission check results in IIS returning an HTTP 403–Access Forbidden response, whereas a failed NTFS permission check results in IIS returning an HTTP 401–Access Denied.
The bottom line is that gatekeepers perform authorization based on the identity of the user or service calling into the gate and attempting to access a specific resource. The value of multiple gates is in-depth security with multiple lines of defense. Table 2.2 summaries the set of gatekeepers and identifies for each one the gates that they are responsible for.
Table 2.2. Gatekeepers responsibilities and the gates they provide
| Gatekeeper | Gates |
|---|---|
| Windows Operating System | Logon rights (positive
and negative, for example "Deny logon locally") Other privileges (for example "Act as part of the operating system") Access checks against secured resources such as the registry and file system. Access checks use ACLs attached to the secure resources, which specify who is and who is not allowed to access the resource and also the types of operation that may be permitted. TCP/IP filtering IP Security |
| IIS | Authentication
(Anonymous, Basic, Digest, Integrated, Certificate) IP address and domain name restrictions (these can be used as an additional line of defense, but should not be relied upon due to the relative ease of spoofing IP addresses). Web permissions NTFS permissions |
| ASP.NET | URL
Authorization File Authorization Principal Permission Demands .NET Roles |
| Enterprise Services | Windows (NTLM /
Kerberos) authentication Enterprise Services (COM+) roles Impersonation levels |
| Web services | Uses gates provided by IIS and ASP.NET |
| Remoting | Uses gates provided by the host. If hosted in ASP.NET it uses the gates provided by IIS and ASP.NET. If hosted in a Windows service, then you must develop a custom solution. |
| ADO.NET | Connection strings. Credentials may be explicit or you may use Windows authentication (for example, if you connect to SQL Server) |
| SQL Server | Server logins Database logins Database object permissions |
By using the various gates throughout the tiers of your application, you can filter out users that should be allowed access to your back-end resources. The scope of access is narrowed by successive gates that become more and more granular as the request proceeds through the application to the back-end resources.
Consider the Internet-based application example using IIS that is shown in Figure 2.4.

Figure 2.4. Filtering users with gatekeepers
Figure 2.4 illustrates the following:
.NET security is layered on top of Windows security. The user centric concept of Windows security is based on security context provided by a logon session while .NET security is based on IPrincipal and IIdentity objects.
In Windows programming when you want to know the security context code is running under, the identity of the process owner or currently executing thread is consulted. With .NET programming, if you want to query the security context of the current user, you retrieve the current IPrincipal object from Thread.CurrentPrincipal.
The .NET Framework uses identity and principal objects to represent users when .NET code is running and together they provide the backbone of .NET role-based authorization.
Identity and principal objects must implement the IIdentity and IPrincipal interfaces respectively. These interfaces are defined within the System.Security.Principal namespace. Common interfaces allow the .NET Framework to treat identity and principal objects in a polymorphic fashion, regardless of the underlying implementation details.
The IPrincipal interface allows you to test role membership through an IsInRole method and also provides access to an associated IIdentity object.
public interface IPrincipal
{
bool IsInRole( string role );
IIdentity Identity {get;}
}
The IIdentity interface provides additional authentication details such as the name and authentication type.
public interface IIdentity
{
string authenticationType {get;}
bool IsAuthenticated {get;}
string Name {get;}
}
The .NET Framework supplies a number of concrete implementations of IPrincipal and IIdentity as shown in Figure 2.5 and described in the following sections.

Figure 2.5. IPrincipal and IIdentity implementation classes
The .NET version of a Windows security context is divided between two classes:
Note
The static WindowsIdentity.GetCurrent()method returns the identity of the currently executing thread, which may or may not be impersonating. This is similar to the Win32 GetUserName API.
These implementations are very simple and are used by applications that do not use Windows authentication and where the application does not need complex representations of a principal. They can be created in code very easily and as a result a certain degree of trust must exist when an application deals with a GenericPrincipal.
If you are relying upon using the IsInRole method on the GenericPrincipal in order to make authorization decisions, you must trust the application that sends you the GenericPrincipal. This is in contrast to using WindowsPrincipal objects, where you must trust the operating system to provide a valid WindowsPrincipal object with an authenticated identity and valid group/role names.
The following types of identity object can be associated with the GenericPrincipal class:
Typically, Thread.CurrentPrincipal is checked in .NET code before any authorization decisions are made. ASP.NET, however, provides the authenticated user's security context using HttpContext.User.
This property accepts and returns an IPrincipal interface. The property contains an authenticated user for the current request. ASP.NET retrieves HttpContext.User when it makes authorization decisions.
When you use Windows authentication, the Windows authentication module automatically constructs a WindowsPrincipal object and stores it in HttpContext.User. If you use other authentication mechanisms such as Forms or Passport, you must construct a GenericPrincipal object and store it in HttpContext.User.
At any given time during the execution of an ASP.NET Web application, there may be multiple identities present during a single request. These identities include:
In the current version of the .NET Framework, Remoting and Web services do not have their own security model. They both inherit the security feature of IIS and ASP.NET.
Although there is no security built into the Remoting architecture, it was designed with security in mind. It is left up to the developer and/or administrator to incorporate certain levels of security in Remoting applications. Whether or not principal objects are passed across Remoting boundaries depends on the location of the client and remote object, for example:
This chapter has introduced the full set of authentication and authorization options provided by the various .NET related technologies. By using multiple gatekeepers throughout your .NET Web application, you will be able to implement a defense-in-depth security strategy. To summarize:
The next chapter, Chapter 3, Authentication and Authorization, provides additional information to help you choose the most appropriate authentication and authorization strategy for your particular application scenario.